<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>工作时间</title>
	<%@include file="/common/commonCSS.jsp" %>
	<%@include file="/common/commonJS.jsp" %>
	<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
</head>
<body >
<div class="main-container" id="main-container">
	<form class="form-horizontal  bv-form" id="incidentForm">
		<div style="display: none">
			<input id="id" name="id"  value="${timetblWorktime.id}"/>
		</div>

		<div class="row">
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 Validform_label control-label no-padding-right">周一上班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="monStarttime" name="monStarttime" placeholder ="格式为HH:mm 如09:00"  datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" type="text" class="form-control" value="${timetblWorktime.monStarttime}" />
					</span>
				</div>
			</div>
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周一下班班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="monEndtime" name="monEndtime" type="text" placeholder ="格式为HH:mm 如09:00"  datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/"class="form-control" value="${timetblWorktime.monEndtime}" />
					</span>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周二上班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="tuesStarttime" name="tuesStarttime" type="text" class="form-control"  placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/"value="${timetblWorktime.tuesStarttime}" />
					</span>
				</div>
			</div>
			<div class="form-group  col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周二下班班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="tuesEndtime" name="tuesEndtime" type="text" class="form-control"  placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.tuesEndtime}" />
					</span>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周三上班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="wenStarttime" name="wenStarttime" type="text" class="form-control"  placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.wenStarttime}" />
					</span>
				</div>
			</div>
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周三下班班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="wenEndtime" name="wenEndtime" type="text" class="form-control"  placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.wenEndtime}" />
					</span>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周四上班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="thursStarttime" name="thursStarttime" type="text" class="form-control"  placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.thursStarttime}" />
					</span>
				</div>
			</div>
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周四下班班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="thursEndtime" name="thursEndtime" type="text" class="form-control"  placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.thursEndtime}" />
					</span>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周五上班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="friStarttime" name="friStarttime" type="text" class="form-control"  placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.friStarttime}" />
					</span>
				</div>
			</div>
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周五下班班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="friEndtime" name="friEndtime" type="text" class="form-control"  placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.friEndtime}" />
					</span>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周六上班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="satStarttime" name="satStarttime" type="text" class="form-control"ignore="ignore" placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.satStarttime}" />
					</span>
				</div>
			</div>
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周六下班班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="satEndtime" name="satEndtime" type="text" class="form-control" ignore="ignore" placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.satEndtime}" />
					</span>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周日上班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="sunStarttime" name="sunStarttime" type="text" class="form-control" ignore="ignore" placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.sunStarttime}" />
					</span>
				</div>
			</div>
			<div class="form-group col-sm-6 col-md-5 ">
				<label class="col-sm-3 control-label no-padding-right">周日下班班时间:</label>
				<div class="col-sm-9">
					<span class="col-xs-11 block input-icon input-icon-right">
						<input id="sunEndtime" name="sunEndtime" type="text" class="form-control" ignore="ignore" placeholder ="格式为HH:mm 如09:00" datatype ="/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/" value="${timetblWorktime.sunEndtime}" />
					</span>
				</div>
			</div>
		</div>


		<div class="row" style="margin-left: 40%;padding-bottom: 28px;margin-top: 25px;">
			<button class="layui-btn" type="button" id="submitBtn">保 存</button>
			<%--<a class="layui-btn layui-btn-normal" href="${webRoot}/sys/timetblworkdate/list">返 回</a>--%>
		</div>
	</form>
</div>
</body>
<script>
    //提交
    $("#submitBtn").click(function () {
        checkFormValid($("#incidentForm"),function () {
            var url ="${webRoot}/sys/timetblworktime/save";
            $.post(url,$("#incidentForm").serialize(),function (result) {
                if(result.code == '0'){
                    if($("#id").val() == ''){
                        alert(result,function () {
                            workdateList(result);
                            closeThisWindow();
                        },function () {
                            $("#submitBtn").reset();
                        });
                    }else {
                        //更新成功，返回List页面
                        toast(result.msg);
                        workdateList(result);
                        //关闭弹框
                        closeThisWindow();
                    }
                }else {
                    alertMsg(result.msg);
                }

            });
        })
    });
    $("input").blur(function(event) {

		var comName =$(this).attr("id");
        var amRawValue;
        var pmRawValue;
        var currCombo;
        if(parseInt(comName.indexOf('Start'))!=-1){
            amRawValue = $(this).val();
            currCombo =$("#"+comName.replace('Start','End'))
//            currCombo = this.baseForm.form.findField(comName.replace('Am','Pm'));
            pmRawValue = currCombo.val();
        }else{
            pmRawValue = $(this).val();
            currCombo = $("#"+comName.replace('End','Start'));
            amRawValue = currCombo.val();
        }
        if(amRawValue&&pmRawValue){
            if(parseInt(amRawValue.split(':')[0])<parseInt(pmRawValue.split(':')[0])){
                if(comName=='monStarttime'){
                    $("input[type='text']").each(function(){
                        var id = $(this).attr("id");
                        if(parseInt(id.indexOf('Start'))!=-1){
                            $(this).val(amRawValue) ;
                        }
                    })
                }
                if(comName=='monEndtime'){
                    $("input[type='text']").each(function(){
                        var id = $(this).attr("id");
                        if(parseInt(id.indexOf('End'))!=-1){
                            $(this).val(pmRawValue) ;
                        }
                    })
                }
                return;
            }else if((parseInt(amRawValue.split(':')[0])==parseInt(pmRawValue.split(':')[0]))&&parseInt(amRawValue.split(':')[1])<parseInt(pmRawValue.split(':')[1])){
                if(comName=='monStarttime'){
                    $("input[type='text']").each(function(){
                        var id = $(this).attr("id");
                        if(parseInt(id.indexOf('Start'))!=-1){
                            $(this).val(amRawValue) ;
                        }
                    })
                }
                if(comName=='monEndtime'){
                    $("input[type='text']").each(function(){
                        var id = $(this).attr("id");
                        if(parseInt(id.indexOf('End'))!=-1){
                            $(this).val(pmRawValue) ;
                        }
                    })
                }
                return;
            }
            currCombo.val("");
            toast("下班时间不能小于上班时间");
        }else{
            if(comName=='monStarttime'){
                $("input[type='text']").each(function(){
                    var id = $(this).attr("id");
                    if(parseInt(id.indexOf('Start'))!=-1){
                        $(this).val(amRawValue) ;
                    }
                })
            }
            if(comName=='monEndtime'){
                $("input[type='text']").each(function(){
                    var id = $(this).attr("id");
                    if(parseInt(id.indexOf('End'))!=-1){
                        $(this).val(pmRawValue) ;
                    }
                })
            }
		}
    })

    function workdateList(result) {
        var userTab=$(parent.document.getElementById("tabContent")).find("#table-list tbody");
        var html ="";
        userTab.find("tr").each(function () {
            var trid = $(this).attr("id");
            if(trid ==result.timetblWorktime.id){
                $(this).remove();
            }
        })

        html+="<tr id='"+result.timetblWorktime.id+"'>";
        html+=" <td style='display: none'>";
        html+="  	<input name='timetblWorktimeIds' value='"+result.timetblWorktime.id+"'/>";
        html+="  </td>";
        html+=" <td>"+result.timetblWorktime.monStarttime+"-"+result.timetblWorktime.monEndtime+"</td>";
        html+=" <td>"+result.timetblWorktime.tuesStarttime+"-"+result.timetblWorktime.tuesEndtime+"</td>";
    	html+=" <td>"+result.timetblWorktime.wenStarttime+"-"+result.timetblWorktime.wenEndtime+"</td>";
    	html+=" <td>"+result.timetblWorktime.thursStarttime+"-"+result.timetblWorktime.thursEndtime+"</td>";
    	html+=" <td>"+result.timetblWorktime.friStarttime+"-"+result.timetblWorktime.friEndtime+"</td>";
    	html+=" <td>"+result.timetblWorktime.satStarttime+"-"+result.timetblWorktime.satEndtime+"</td>";
    	html+=" <td>"+result.timetblWorktime.sunStarttime+"-"+result.timetblWorktime.sunEndtime+"</td>";

        html+="<td> <div class=\" btn-group \"> " +
            "<button class=\"layui-btn layui-btn-danger layui-btn-small\" type=\"button\" onclick=\"addTimetblworktime('"+result.timetblWorktime.id+"')\"><i class=\"layui-icon\">&#xe642;</i> 编辑</button>";
        html+="<button class='layui-btn layui-btn-danger layui-btn-small' type='button' onclick=\"deleteWorktimeById('"+result.timetblWorktime.id+"')\"><i class='layui-icon'>&#xe640;</i>删除</button>";
        html+="</div>  </td> </tr>";
        userTab.append(html);
    }

</script>
</html>